const focusService = require('../service/like.service')

class focusController {
    async create(ctx, next) {
        const { followedId } = ctx.query
        const { id } = ctx.user
        const result = await focusService.create(id, followedId)
        ctx.body = result
    }

    async remove(ctx, next) {
        const { followedId } = ctx.query
        const { id } = ctx.user
        console.log('关注人id',id,followedId)
        const result = await focusService.detele(id, followedId)
        ctx.body = result
    }

    // 
    async followedList(ctx, next) {
        const { userId } = ctx.query
        const result = await focusService.followedList(userId)
        const imageBlob = result[0].avatar
        const imageBuffer = Buffer.from(imageBlob)
        const imageBase64 = imageBuffer.toString('base64')
        result[0].avatar = imageBase64.replace(/[\r\n]/g, "")
        ctx.body = result
    }

    async followerList(ctx, next) {
        const { userId } = ctx.query
        const result = await focusService.followerList(userId)
        const imageBlob = result[0].avatar
        const imageBuffer = Buffer.from(imageBlob)
        const imageBase64 = imageBuffer.toString('base64')
        result[0].avatar = imageBase64.replace(/[\r\n]/g, "")
        ctx.body = result
    }
}

module.exports = new focusController()
